package com.polaris.live.dialog.common

import android.content.Context
import android.view.View
import com.lxj.xpopup.core.CenterPopupView
import com.polaris.live.R
import com.polaris.live.common.ext.setOnSingleClickListener
import com.polaris.live.databinding.DialogCommonSureDetailBinding
import com.polaris.live.im.sfs.bean.chat.ext.RouterHighlight
import com.polaris.live.utils.route.RouterUtils

/**
 * CommonSureDetailDialog
 *
 * @author Created by 半仙 on 2023/11/16/016 19:40
 */
class CommonSureDetailDialog(
    context: Context,
    private val mTitle: String,
    private val mDetail: String?,
    private val mConfirmText: String?,
    private val mHighlight: List<RouterHighlight>? = null,
    private val mOnSetClick: (() -> Unit)? = null,
) : CenterPopupView(context) {
    override fun getImplLayoutId(): Int {
        return R.layout.dialog_common_sure_detail
    }

    private lateinit var mBinding: DialogCommonSureDetailBinding

    override fun onCreate() {
        super.onCreate()
        mBinding = DialogCommonSureDetailBinding.bind(popupImplView)

        mBinding.tvTitle.text = mTitle

        if (mDetail == null) {
            mBinding.tvDetail.visibility = View.GONE
        } else {
            mBinding.tvDetail.text = mDetail
            mBinding.tvDetail.visibility = View.VISIBLE
        }

        if (mHighlight != null && mDetail != null) {
            RouterUtils.handleText(mBinding.tvDetail, mDetail, mHighlight)
        }

        if (mConfirmText != null) {
            mBinding.tvConfirm.text = mConfirmText
        }

        mBinding.tvConfirm.setOnSingleClickListener {
            mOnSetClick?.invoke()
            dismiss()
        }
    }
}